/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

import com.click.app.Functions;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author orgale
 */
@Entity
@Table(name = "material_supplier")
@NamedQueries({@NamedQuery(name = "MaterialSupplier.findAll", query = "SELECT m FROM MaterialSupplier m"), @NamedQuery(name = "MaterialSupplier.findByIdMaterial", query = "SELECT m FROM MaterialSupplier m WHERE m.materialSupplierPK.idMaterial = :idMaterial"), @NamedQuery(name = "MaterialSupplier.findByIdSupplier", query = "SELECT m FROM MaterialSupplier m WHERE m.materialSupplierPK.idSupplier = :idSupplier"), @NamedQuery(name = "MaterialSupplier.findByPrecio", query = "SELECT m FROM MaterialSupplier m WHERE m.precio = :precio"), @NamedQuery(name = "MaterialSupplier.findByDate", query = "SELECT m FROM MaterialSupplier m WHERE m.date = :date")})
public class MaterialSupplier extends BaseObject implements Serializable {
    private static final long serialVersionUID = 1L;
    
    
    protected MaterialSupplierPK materialSupplierPK;
    
    private Double precio;
    private Date date;
    private Material material;
    private Supplier supplier;

    public MaterialSupplier() { }

    public MaterialSupplier(MaterialSupplierPK materialSupplierPK) {
        this.materialSupplierPK = materialSupplierPK;
    }

    public MaterialSupplier(int idMaterial, int idSupplier) {
        this.materialSupplierPK = new MaterialSupplierPK(idMaterial, idSupplier);
    }

    @EmbeddedId
    public MaterialSupplierPK getMaterialSupplierPK() {
        return materialSupplierPK;
    }

    public void setMaterialSupplierPK(MaterialSupplierPK materialSupplierPK) {
        this.materialSupplierPK = materialSupplierPK;
    }

    @Column(name = "precio")
    public Double getPrecio() {
        return Functions.getDouble3Decimal(precio);
    }

    public void setPrecio(Double precio) {
        this.precio = Functions.getDouble3Decimal(precio);
    }

    @Column(name = "date")
    @Temporal(TemporalType.DATE)
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @JoinColumn(name = "id_material", referencedColumnName = "id_material", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    public Material getMaterial() {
        return material;
    }
    
    public void setMaterial(Material material) {
        this.material = material;
    }

    @JoinColumn(name = "id_person", referencedColumnName = "id_person", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    public Supplier getSupplier() {
        return supplier;
    }

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (materialSupplierPK != null ? materialSupplierPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MaterialSupplier)) {
            return false;
        }
        MaterialSupplier other = (MaterialSupplier) object;
        if ((this.materialSupplierPK == null && other.materialSupplierPK != null) || (this.materialSupplierPK != null && !this.materialSupplierPK.equals(other.materialSupplierPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.MaterialSupplier[materialSupplierPK=" + materialSupplierPK + "]";
    }

}
